package com.huawei.hms.framework.network.restclient.hwhttp;

import com.huawei.hms.framework.network.restclient.Headers;
import java.io.Closeable;
import java.io.IOException;

public class Response implements Closeable {
    private ResponseBody body;
    private int code;
    private Headers headers;
    private String message;

    public static final class Builder {
        private ResponseBody body;
        private int code;
        private Headers headers;
        private String message;

        public Builder body(ResponseBody responseBody) {
            this.body = responseBody;
            return this;
        }

        public Builder headers(Headers headers) {
            this.headers = headers;
            return this;
        }

        public Builder code(int i) {
            this.code = i;
            return this;
        }

        public Builder message(String str) {
            this.message = str;
            return this;
        }

        public Response build() {
            return new Response();
        }
    }

    private Response(Builder builder) {
        this.body = builder.body;
        this.headers = builder.headers;
        this.code = builder.code;
        this.message = builder.message;
    }

    public void close() throws IOException {
        if (this.body != null) {
            this.body.close();
            this.body = null;
        }
    }

    public Headers getHeaders() {
        return this.headers;
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public ResponseBody getBody() {
        return this.body;
    }

    public boolean isOK() {
        return this.code == 200;
    }

    public boolean isSuccessful() {
        return this.code >= 200 && this.code < 300;
    }
}
